﻿using AutoMapper;
using B.S.BaseData.Api.Write.Applicantion.Command.HospitalCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.AI;
using MediatR;
using static B.S.BaseData.Api.Write.Applicantion.Command.HospitalCommand.HistoryOfMedicalVisitsUpdateCommand;

namespace B.S.BaseData.Api.Write.Applicantion.CommandHandler.HospitalCommandHandler
{
    public class HistoryOfMedicalVisitsUpdateCommandHandler : IRequestHandler<HistoryOfMedicalVisitsUpdateCommand, APIResult<int>>
    {
        private readonly IBaseRepository<HistoryOfMedicalVisitsModel> _repository;
        private readonly IMapper _mapper;
        public HistoryOfMedicalVisitsUpdateCommandHandler(IBaseRepository<HistoryOfMedicalVisitsModel> repository, IMapper mapper)
        {
            _repository = repository;
            _mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(HistoryOfMedicalVisitsUpdateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var list = _mapper.Map<HistoryOfMedicalVisitsModel>(request);
            result.Code = ApiEnum.Fail;
            result.Msg = "就诊记录修改成功";
            result.Data = await _repository.UpdateAsync(list);
            return await Task.FromResult(result);
        }
    }
}
